package com.example.lanqiaodemo1.java12;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class TestInput {
    public static void main(String[] args) {
        int[] iArray = new int[20];
        byte[] b = new byte[1024];//用于存取字节流中的字节
        int sum = 0, count = 0;
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 20; i++) {
            iArray[i] = sc.nextInt();
            sum = sum + iArray[i];
        }
        sc.close();
        System.out.println("sum=" + sum);
        FileOutputStream fout = null;//文件字节输入流
        FileInputStream fin = null;//文件字节输出流
        try {
            fout = new FileOutputStream("d:\\my.bin");
            for (int i = 0; i < 20; i++) {
                fout.write((String.valueOf(iArray[i])).getBytes());
            }
            fout.close();


            fin = new FileInputStream("d:\\my.bin");
            while ((count = fin.read(b)) != -1) {
                System.out.println(new String(b, 0, count));//打印
            }
            fin.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fout != null) {
                try {
                    fout.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fin != null) {
                try {
                    fin.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
